
import get from '@dfeidao/atom-web/local/get';
import fire_component_msg from '@dfeidao/atom-web/msg/fire';

import anim from '@dfeidao/atom-web/animation/anim';
import play from '@dfeidao/atom-web/animation/play';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';
// import show_loading from '../../atom-web/show-loading';
// import hide_loading from '../../atom-web/hide-loading';
export default async function a002(fd: IFeidaoAiBrowserComponent, args: { currentTarget: HTMLElement }) {
	// 保存
	const syid = fd.data.node.querySelector<HTMLInputElement>('#sysid').value;
	const r_name = fd.data.node.querySelector<HTMLInputElement>('#r_name').value;
	const tabname = fd.data.node.querySelector<HTMLInputElement>('#tabname').value;
	const fid = fd.data.node.querySelector<HTMLInputElement>('#fid').value;
	const ftitle = fd.data.node.querySelector<HTMLInputElement>('#ftitle').value;
	const s_field = fd.data.node.querySelector<HTMLInputElement>('#s_field').value;
	const s_title = fd.data.node.querySelector<HTMLInputElement>('#s_title').value;
	const moid = fd.data.node.querySelector<HTMLInputElement>('#moid').value;
	const id = args.currentTarget.getAttribute('data-feidao-id');


	const prid = get(fd, 'productid');


	if (!r_name) {
		await error('请完善角色类型名称');
		// fire_component_msg('zjc-000001', 'ec-001', 'please', '请完善角色类型名称');
		return;
	}
	if (!tabname) {
		await error('请完善主档表名');
		// fire_component_msg('zjc-000001', 'ec-001', 'please', '请完善主档表名');
		return;
	}
	if (!fid) {
		await error('请完善主档属性字段');
		// fire_component_msg('zjc-000001', 'ec-001', 'please', '请完善主档属性字段');
		return;
	}
	if (!ftitle) {
		await error('请完善主档属性字段标题');
		// fire_component_msg('zjc-000001', 'ec-001', 'please', '请完善主档属性字段标题');
		return;
	}
	if (!s_field) {
		await error('请完善描述字段');
		// fire_component_msg('zjc-000001', 'ec-001', 'please', '请完善描述字段');
		return;
	}
	if (!s_title) {
		await error('请完善描述字段标题');
		// fire_component_msg('zjc-000001', 'ec-001', 'please', '请完善描述字段标题');
		return;
	}
	if (!moid) {
		await error('请完善引用模型');
		// fire_component_msg('zjc-000001', 'ec-001', 'please', '请完善引用模型');
		return;
	}
	if (!syid) {
		await error('请完善systemid');
		// fire_component_msg('zjc-000001', 'ec-001', 'please', '请完善systemid');
		return;
	}
	let query;
	if (get(fd, 'role_type_name') === r_name) {
		query = {
			_id: id,
			tablename: tabname,
			field: fid,
			fieldtitle: ftitle,
			search_field: s_field,
			search_title: s_title,
			modelid1: moid,
			systemid: syid,
			productid: prid
		};
	} else {
		query = {
			_id: id,
			role_type_name: r_name,
			tablename: tabname,
			field: fid,
			fieldtitle: ftitle,
			search_field: s_field,
			search_title: s_title,
			modelid1: moid,
			systemid: syid,
			productid: prid
		};
	}
	// show_loading();
	// const res = await nodejs(url, './permissions/role_type_upd', query, false, false);
	const res = await nodejs('role-type/zj-000004/s002', query);
	// hide_loading();
	if (res === 'repert') {
		await error('角色类型名称重复，无法保存');
		return;
	}
	if (res === 'success') {
		success('保存成功');
		// fire_component_msg('zjc-000001', 'ec-001', 'success', '保存成功');
		const aim_node = document.getElementById('zj-000004');
		play(anim(aim_node, {
			repeat: 0,
			duration: 800,
			units: 'px',
			delay: 0,
			easing: 'ease', // 动画效果 默认为'ease'
			precent: 0 // 动画暂停时长 单位是ms
		}, {
				right: {
					start: 0,
					end: -676
				}
			}));
		fire_component_msg('zj-000001', 'ec-002');

	} else {
		await error('保存失败');
		// fire_component_msg('zjc-000001', 'ec-001', 'fail', '保存失败');
	}
}
